/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package strategies;

import dao.CountryDAO;
import exceptions.DatabaseException;
import java.util.List;
import wrappers.CountryWrap;
import wrappers.DepartmentWrap;

/**
 *
 * @author KAV
 */
public class DepartmentsEditPageStrategy extends EditPageStrategy {

    @Override
    protected void commitRow(Object e) throws DatabaseException {
        DepartmentWrap ew;
        if (e == null) {
            ew = new DepartmentWrap();
        } else {
            ew = (DepartmentWrap) e;
        }

        op.putBlockLabel("edit_title", "Title");
        op.putTextField("edit_title", ew.getTitle());
        op.putBlockLabel("edit_country", "Country");
        op.echo("<select type=\"text\" id=\"edit_country\" name=\"edit_country\"  size=\"1\">");
        dao = new CountryDAO();
        List<Object> list = dao.findAll();
        for (Object o : list) {
            CountryWrap obj = (CountryWrap) o;
            op.putSelectOption(obj.getViewId().getValue(), obj.getViewTitle().getValue(), ew.getCountry() == Integer.parseInt(obj.getViewId().getValue())/*country.toString().compareTo(obj.getViewId().toString()) == 0*/);
        }
        op.echo("</select><div class=\"clear\"></div>");
    }

    @Override
    protected Object writeInfo() {
        DepartmentWrap ew = (DepartmentWrap) e;
        return ew;
    }
}
